# -*- coding: utf-8 -*-
"""
______________________________
  Author: 安智军
  Email :  1010666711@qq.com
   Time : 2023/8/6 15:57
    File: login_page.py
Software: PyCharm
______________________________
"""
from .base_page import BaesPage
from .home_page import HomePage
import yaml
import time


class LoginPage(BaesPage):

    def login(self):
        """
        登录方法
        :return:
        """
        # 1，访问微信登录首页
        # self.driver.get("https://work.weixin.qq.com/wework_admin/frame")
        self.driver.get("https://work.weixin.qq.com/wework_admin/frame#index")
        # while True:
        #     if not self.driver.current_url.__contains__("login"):
        #         break
        # cookies = self.driver.get_cookies()
        #
        # # 将获取到的 cookies 存放到本地的 yaml 文件中
        # with open("./cookies.yaml", "w") as s:
        #     yaml.safe_dump(data=cookies, stream=s)


        # 2、获取本地的 cookies
        with open("./cookies.yaml", "r") as f:
            cookies = yaml.safe_load(f)
        # 3、植入 cookies 实现免登录
        for ck in cookies:
            self.driver.add_cookie(ck)

        # 页面刷新一下 就可以显示登录状态了
        self.driver.refresh()
        # 将 driver 传递给首页
        return HomePage(self.driver)
